package ProTest;

/**
 * YangHuiTriangle
 *
 * @author byc
 * @date 2021-08-20
 */
public class YangHuiTriangle {
    public static void main(String[] args) {
        //杨辉三角 高度
        int lengthMax = 13;
        int[][] arr1 = new int[lengthMax][];
        //创建一个二维数组
        for (int i = 0; i < lengthMax; i++) {
            arr1[i] = new int[i+1];
        }
        //填充两边的1
        for (int i = 0; i < lengthMax; i++) {
            arr1[i][0] = 1;
            arr1[i][(arr1[i].length) - 1] = 1;
        }
        //从第3层开始 nums[n][i] = nums[n-i][i-1] + nums[n-1][i]
        for (int i = 2; i < lengthMax; i++) {
            for (int j = 1; j < arr1[i].length - 1; j++) {
                arr1[i][j] = arr1[i-1][j-1] + arr1[i-1][j];
            }
        }
        //打印
        for (int i = 0; i < arr1.length; i++) {
            for (int k = 0; k < arr1.length-i; k++) {
                System.out.print("\t");
            }
            for (int j = 0; j < arr1[i].length; j++) {
                System.out.print(arr1[i][j] +"\t\t");
            }
            System.out.println();
        }

    }
}
